package client.adminGUI;

import client.backend.Connection;
import client.adminGUI.GUIAdmin;

import java.awt.event.*;
import java.awt.Dimension;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.Color;


public class BottomPanel extends JPanel implements ActionListener{
	private JButton quit;
	private static BottomPanel instance;
	private JLabel message;
	
	public static final int HEIGHT=80;

	/**
	 * This is the default constructor
	 */
	public BottomPanel() {
		super();
		initialize();
	}

	/**
	 * This method initialises BottomPanel
	 */
	private void initialize() {
		quit = new JButton("Quit");
		this.setLayout(null);

		quit.setLocation(GUIAdmin.WIDTH-120, 10);
		quit.setSize(new Dimension(100, 30));
		quit.setPreferredSize(new Dimension(100, 30));
		
		message = new JLabel("Welcome to ACE!");
		message.setBounds(GUIAdmin.WIDTH/2-100,(HEIGHT-20)/3,300,20);
		this.setBounds(0, GUIAdmin.HEIGHT-HEIGHT, GUIAdmin.WIDTH, HEIGHT);
		
		this.add(quit);
		this.add(message);
		
		this.setBackground(Color.black);
		
		quit.addActionListener(this);
	}
	
	/**
	 * Catch actions performed
	 */
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == quit) {
			Connection.getInstance().quit();
			System.exit(0);
		}
	}
	
	/**
	 * Set the bottom message
	 * @param text	New message text
	 */
	public void setMessage(String text){
		message.setText(text);
	}
	
	/**
	 * Instance getter
	 * @return	Only instance of BottomPanel
	 */
	public static BottomPanel getInstance() {
		if (instance == null) {
			instance = new BottomPanel();
		}
		return instance;
	}
}



